package com.badshun.game;

import com.badlogic.gdx.*;
import com.badlogic.gdx.graphics.*;
import com.badshun.stage.*;
import com.badshun.player.*;
import com.badshun.box2d.*;
import com.badshun.ui.*;
import com.badshun.map.*;
import com.badshun.sound.*;
import com.badlogic.gdx.audio.*;

public class MainGame extends ApplicationAdapter {
	private OrthographicCamera camera;
	private GameStage gameStage;
	private EnvironmentStage stage;
	private MainCityStage mainCityStage;
	private MainCityRoom1Stage mainCityRoom1Stage;
	private MainPlayer mainPlayer;
	private Box2DWorld b2dWorld;
	private EnvironmentStageManager esm;
	private NPCPlayersManager npm;
	private GameBackgroundMusic gbm;
	
	private Music bg1;
	
	@Override
	public void create() {
		camera = new OrthographicCamera();
		camera.setToOrtho(false,Gdx.graphics.getWidth() / 2,Gdx.graphics.getHeight() / 2);
		
		gbm = new GameBackgroundMusic();
		
		bg1 = gbm.createMusic("bgm/bg1.mp3");
		//bg1.play();
		bg1.setLooping(true);
		bg1.setVolume(1);
		
		b2dWorld = new Box2DWorld(camera);
		
		esm = new EnvironmentStageManager();
		
		mainPlayer = new MainPlayer(esm,camera,b2dWorld);
		
		npm = new NPCPlayersManager();
		
		gameStage = new GameStage();
		gameStage.createGameUI(mainPlayer,npm,camera,b2dWorld);
		
		
		esm.createMcs(mainPlayer,npm,camera,b2dWorld);
		
		b2dWorld.setContactListener(mainPlayer,esm.mcs.npm.npcs,esm);
		
		Gdx.input.setInputProcessor(gameStage.stage);
	}
	
	@Override
	public void render() {
		Gdx.gl20.glClear(Gdx.gl20.GL_COLOR_BUFFER_BIT);
		Gdx.gl20.glClearColor(0,0,0,1);
		
		camera.position.set(mainPlayer.position.x,mainPlayer.position.y,0);
		
		esm.act();
		esm.draw();
		
		mainPlayer.render();
		
		gameStage.act();
		gameStage.draw();
		
		b2dWorld.render();
	}
}
